using System.Xml;

namespace Kotonoha.Server.Xml {
    public abstract class ElementHandler {
        protected internal readonly string name;

        protected ElementHandler(string name) {
            this.name = name;
        }

        public void read(XmlReader reader) {
            if (OnStart != null) {
                OnStart.Invoke();
            }
            readAttributes(reader);
            reader.ReadStartElement(name);
            readBody(reader);
            reader.ReadEndElement();
            if (OnEnd != null) {
                OnEnd.Invoke();
            }
        }

        public event SimpleAction OnStart;
        public event SimpleAction OnEnd;

        protected virtual void readAttributes(XmlReader reader) {}

        protected abstract void readBody(XmlReader reader);
    }
}